package com.contact;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.android.ocean.util.common.StringUtil;
import com.chat.adapter.VedioListAdapter;
import com.common.method.ServerPath;
import com.http.ADListTask;
import com.http.CityIDTask;
import com.http.NetCallBack;
import com.matang.R;
import com.util.AppUtil;

/**
 * @author Administrator
 *视频列表
 */
public class VedioListActivity extends BaseActivity {
	
	private ListView listVedio;
	private String cityCatID;
	private VedioListAdapter adapter;
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.vidio_list);
		init();
	}
	private void init() {
		
		findViews();
		initPaneData();
		findView();
		setData();
		loadADList();
	//loadCityID();
		setOnClicKer();
		
		
		
	}
	
	protected void initPaneData() {

		super.initPaneData();
		header.headLeftTv.setText("返回");
		
		header.headTitleTv.setText("马塘视频");
		
		header.headLeftTv.setVisibility(View.VISIBLE);
		header.headRightTv.setVisibility(View.GONE);
		header.headLeftTv.setOnClickListener(new OnClickListener() {
			
	
			public void onClick(View view) {
				VedioListActivity.this.finish();
				
			}
		});


	}

	private void setOnClicKer() {
		listVedio.setOnItemClickListener(new OnItemClickListener() {

		
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				ADData adData = (ADData) arg0.getAdapter().getItem(position);
				Intent intent = new Intent();
				intent.setClass(VedioListActivity.this,
						VideoPlayerUserActivity.class);
				UserVAudio userVAudio = new UserVAudio();
				userVAudio.videoUrl =adData.videoUrl;
				intent.putExtra("uvData", userVAudio);
				startActivity(intent);
				
			}
		});
		
	}
	private void setData() {
		if (adapter == null) {
			adapter = new VedioListAdapter(this);
		}
		listVedio.setAdapter(adapter);
		
	}
	private void loadADList(){
		
		new ADListTask(adListCallBack).execute("13", "1");
	}
	private void findView() {
		listVedio = (ListView) findViewById(R.id.list_vedio);
		
	}
	
	public void loadCityID() {
		showProgressDialog("数据加载中…………");
		new CityIDTask(cityIDCallBack).execute();

	}

	
	NetCallBack cityIDCallBack = new NetCallBack() {

		@Override
		public void onSuccess(Object... obj) {
			dismissProgressDialog();
			if (ObjTool.isNotNull(obj)) {
				cityCatID = obj[0].toString();

				System.out.println("cityID---------:" + cityCatID);
			}
			loadADList();
		}

	
		public void onError(Object... obj) {
			dismissProgressDialog();
			AppUtil.tsMsg(mContext, "获取默认城市CatID失败");
			
		}
	};

	
	NetCallBack adListCallBack = new NetCallBack() {

		@Override
		public void onSuccess(Object... obj) {
			dismissProgressDialog();
			if (ObjTool.isNotNull(obj)) {
		//		SpCatIDUtil.save(cityCatID);

				ArrayList<ADData> tmpAdList = (ArrayList<ADData>) obj[0];
				if (tmpAdList != null) {
					adapter.addData(tmpAdList);
				}
			
			} else {
				

				AppUtil.tsMsg(mContext, "CatID=" + cityCatID + "下没有节目单数据");
			}
		}

		@Override
		public void onError(Object... obj) {
			dismissProgressDialog();
			AppUtil.tsMsg(mContext, "CatID=" + cityCatID + "下没有节目单数据");
			
		}
	};


}
